package com.example.ex05;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.webkit.WebView.FindListener;
import android.widget.RemoteViews;

public class mywidget extends AppWidgetProvider{
	
	private AppWidgetManager manager;
	private RemoteViews remoteViews;
	public static mywidget instance;
	private Context context;
	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager,
			int[] appWidgetIds) {
		// TODO Auto-generated method stub
		instance = this;
		this.context = context;
		manager = appWidgetManager;
		remoteViews = new RemoteViews(context.getPackageName(),R.layout.wiget_layout);
		Intent clickInent = new Intent( context,MainActivity.class );
		PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, clickInent,0 );
		remoteViews.setOnClickPendingIntent( R.id.wigetText, pendingIntent);
		appWidgetManager.updateAppWidget(appWidgetIds,remoteViews);
		super.onUpdate(context, appWidgetManager, appWidgetIds);
	}
	
	public void updateWidget(String brocastMsg) {
		remoteViews.setTextViewText(R.id.wigetText, brocastMsg);
		manager.updateAppWidget(new ComponentName(context, mywidget.class),remoteViews);
	}

}
